#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@his-pc>
#
# Distributed under terms of the MIT license.

"""

"""


class Solution:
    """
    @param nums: The integer array you should partition
    @param k: An integer
    @return: The index after partition
    """
    def partitionArray(self, nums, k):
        # write your code here
        if not nums:
            return 0

        l = len(nums)

        # [start, end] is all close
        start, end = 0, l-1
        while start < end + 1:
            num = nums[start]
            if num < k:
                start += 1
            else:
                nums[start], nums[end] = nums[end], nums[start]
                end -= 1
        # print('start is %s' % start)
        return start


def main():
    print("start main")
    s = Solution()
    r = s.partitionArray([1, 2, 3], 4)
    print(r)

    r = s.partitionArray([4, 5, 1], 4)
    print(r)

if __name__ == "__main__":
    main()
